package com.baosight.risk.web.rifi;

import com.baosight.risk.api.rifi.RifiRiskFinishService;
import com.baosight.risk.api.riim.RiimRiskImportService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.base.entity.MultipleUpdateStatus;
import com.baosight.risk.common.annotation.Log;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.common.utils.ExcelUtil;
import com.baosight.risk.common.utils.StringUtils;
import com.baosight.risk.service.rifi.entity.RifiEvaluate;
import com.baosight.risk.service.rifi.entity.RifiRiskFinish;
import com.baosight.risk.service.rifi.vo.RifiEvaluateVO;
import com.baosight.risk.service.rifi.vo.RifiEvaluateVO2;
import com.baosight.risk.service.rifi.vo.RifiFinishVO;
import com.baosight.risk.service.riim.entity.RiimRiskImport;
import com.baosight.risk.service.riim.vo.RiimRiskImportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/rifi/finish")
@Api(value = "风险结题", description = "风险结题", produces = MediaType.APPLICATION_JSON)
public class RifiRiskFinishController extends BaseController {
    @Autowired
    private RifiRiskFinishService rifiRiskFinishService;
    @Autowired
    private RiimRiskImportService importService;


    @RequestMapping("/selectList")
    @Log(title = "查询风险结题列表")
    @ApiOperation("查询风险结题列表")
    public AjaxResult selectList(RiimRiskImportVO riimRiskImport) {
        startPage();
        return getResultPage(rifiRiskFinishService.selectList(riimRiskImport));
    }

    @GetMapping("/rifiEvaluate")
    @Log(title = "获取重点风险管理能力测评-填写")
    @ApiOperation("获取重点风险管理能力测评-填写")
    public AjaxResult rifiEvaluate(RifiRiskFinish  finish) {
        return success("成功", rifiRiskFinishService.rifiEvaluate(finish));
    }

    @PostMapping("/saveRifiEvaluate")
    @Log(title = "保存重点风险管理能力测评-填写")
    @ApiOperation("保存重点风险管理能力测评-填写")
    public AjaxResult saveRifiEvaluate(@RequestBody RifiEvaluateVO rifiEvaluateVO) {
        Integer integer = rifiRiskFinishService.saveRifiEvaluate(rifiEvaluateVO);
        return toAjax(integer);

    }

    @GetMapping("/getRifiFinish")
    @Log(title = "获取风险结题申请")
    @ApiOperation("获取风险结题申请")
    public AjaxResult getRifiFinish(RiimRiskImport riimRiskImport) {

        return success("成功", rifiRiskFinishService.getFinishByImportId(riimRiskImport));

    }

    @PostMapping("/saveRifiFinish")
    @Log(title = "保存风险结题申请")
    @ApiOperation("保存风险结题申请")
    public AjaxResult saveRifiFinishById(@RequestBody RifiFinishVO rifiFinishVO) {
        rifiRiskFinishService.saveRifiFinish(rifiFinishVO);
        return success("保存成功");
    }

    @PostMapping("selectListByIds")
    @ApiOperation("查询风险结题列表")
    public AjaxResult selectList(@RequestBody List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return error("系统出错啦!没有数据。");
        }
        return success(importService.getByIds(ids));
    }

    @GetMapping("/selectOverList")
    @Log(title = "已结题查询")
    @ApiOperation("已结题查询")
    public AjaxResult selectOverList(RifiRiskFinish riskFinish) {
        startPage();
        return getResultPage(rifiRiskFinishService.selectOverList(riskFinish));
    }

//    @GetMapping("/issuedEvaluate")
//    @Log(title = "下发能力测评")
//    @ApiOperation("下发能力测评")
//    public AjaxResult issuedEvaluate(@RequestParam("importId") String importId) {
//        rifiRiskFinishService.doIssuedEvaluate(importId);
//        return success();
//    }

    @PostMapping("/doSubmit")
    @Log(title = "提交")
    @ApiOperation("提交结题申请")
    public AjaxResult doSubmit(@RequestBody RiimRiskImport riimRiskImport) throws Exception {
        //工作流
        rifiRiskFinishService.doSubmit(riimRiskImport);
        return success("提交成功！待领导审核");
    }

    @GetMapping("/getRifiFinishOver")
    @Log(title = "获取风险结题申请")
    @ApiOperation("获取风险结题申请")
    public AjaxResult getRifiFinish(RifiRiskFinish finish) {

        return success("成功", rifiRiskFinishService.getRifiFinishOver(finish));

    }

    @GetMapping("/pushFinish")
    @ApiOperation("风险结题推送")
    public AjaxResult pushFinish(String finishId) {
        Map returnMap = rifiRiskFinishService.pushFinish(finishId);
        if ("1".equals(returnMap.get("status"))) {
            return success();
        }
        return error(returnMap.get("msg").toString());
    }
}



